<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        style="width: 180px;"
        class="filter-item"
        placeholder="请输入提现单号"
        v-model="queryForm.txNo"
      >
      </el-input>
      <el-input
        style="width: 180px;"
        class="filter-item"
        placeholder="请输入用户手机号"
        v-model="queryForm.phone"
      >
      </el-input>
      <el-button
        class="filter-item"
        @click="doQuery"
        type="primary"
        icon="el-icon-search"
        >查询</el-button
      >
    </div>
    <el-table
      v-loading="loading"
      @sort-change="handleSortChange"
      :data="records"
      style="width: 100%"
    >
      <el-table-column prop="rowId" label="ID" width="100" align="center">
      </el-table-column>
      <el-table-column prop="txNo" label="提现单号" width="250" align="center">
      </el-table-column>
      <el-table-column
        prop="nickname"
        label="用户昵称"
        width="150"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="phone" label="手机号" width="150" align="center">
      </el-table-column>
      <el-table-column
        prop="txAmount"
        label="提现金额"
        width="200"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="txTypeName"
        label="提现方式"
        width="150"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="txFee" label="手续费" width="150" align="center">
      </el-table-column>
      <el-table-column
        prop="applyTime"
        label="申请时间"
        width="250"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="finishTime"
        label="审核时间"
        width="250"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="status"
        label="提现状态"
        width="150"
        align="center"
      >
        <template slot-scope="scope">
          {{ Dicts.TX_STATUS[scope.row.status] }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="操作"
        class-name="small-padding"
        width="300"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            v-permission="'userAccountWithDraw:detail'"
            size="mini"
            type="default"
            @click="handleQueryById(scope.row, 'published')"
            icon="el-icon-search"
            circle
            title="查看详情"
          ></el-button>
          <el-button
            v-permission="'userAccountWithDraw:approve'"
            size="mini"
            type="success"
            v-if="scope.row.status == 0"
            @click="approveApply(scope.row)"
            icon="el-icon-check"
            circle
            title="通过"
          ></el-button>
          <el-button
            v-permission="'userAccountWithDraw:reject'"
            size="mini"
            type="danger"
            v-if="scope.row.status == 0"
            @click="rejectDialog(scope.row.rowId)"
            icon="el-icon-close"
            circle
            title="拒绝"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryForm.current"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="queryForm.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="queryForm.total"
      >
      </el-pagination>
    </div>

    <el-dialog
      :title="`审核说明`"
      :visible.sync="dialogRejectFormVisible"
      width="30%"
    >
      <el-form
        :model="rejectForm"
        label-width="90px"
        :rules="rejectFormRules"
        ref="rejectForm"
      >
        <el-form-item label="审核说明" prop="remark">
          <el-input type="textarea" v-model="rejectForm.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogRejectFormVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="rejectOrder"
          v-show="rejectOrderButton"
          >确 定</el-button
        >
      </div>
    </el-dialog>

    <!-- 详情弹出框 -->
    <el-dialog
      :title="`账户提现申请详情`"
      :visible.sync="dialogShowFormVisible"
      width="50%"
    >
      <el-form :model="showForm" label-width="120px" ref="showForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="提现单号:" prop="txNo">
              {{ showForm.txNo }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审核说明:" prop="remark">
              {{ showForm.remark }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="用户名称:" prop="realName">
              {{ showForm.realName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号:" prop="phone">
              {{ showForm.phone }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="提现方式:" prop="txTypeName">
              {{ showForm.txTypeName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="提现金额:" prop="txAmount">
              {{ showForm.txAmount }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="提现手续费:" prop="txFee">
              {{ showForm.txFee }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="提现开户名:" prop="txAccountName">
              {{ showForm.txAccountName }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="提现卡号:" prop="txCardNo">
              {{ showForm.txCardNo }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="提现银行名:" prop="txBankName">
              {{ showForm.txBankName }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="提现状态:" prop="status">
              <template slot-scope="scope">
                {{ Dicts.TX_STATUS[showForm.status] }}
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="最终打款金额:" prop="finallyAmount">
              {{ showForm.finallyAmount }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="审核人姓名:" prop="checkName">
              {{ showForm.checkName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审核时间:" prop="checkTime">
              {{ showForm.checkTime }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="approveApplyStatus(showForm.rowId, showForm.status)"
          v-show="approveShow"
          >审核</el-button
        >
        <el-button @click="dialogShowFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  queryUserAccountWithDrawCashApply,
  queryUserAccountWithDrawCashApplyDetail,
  rejectAccountWithDrawCashApply,
  approveAccountWithDrawCashApply
} from '@/api/account'

export default {
  name: 'userAccountWithDrawCashApply',
  data() {
    return {
      loading: false,
      dialogShowFormVisible: false,
      dialogRejectFormVisible: false,
      rejectOrderButton: true,
      approveShow: true,
      rejectFormRules: {
        remark: [{ required: true, message: '请输入拒绝原因', trigger: 'blur' }]
      },
      rejectForm: [],
      showForm: [],
      queryForm: {
        current: 1,
        pages: 0,
        total: 0,
        size: 10,
        importance: undefined,
        title: undefined
      },
      transCodeOptions: Dicts.TRANS_CODE,
      records: []
    }
  },
  created() {
    this.doQuery()
  },
  methods: {
    handleSortChange({ column, prop, order }) {
      this.queryForm.ascs = ''
      this.queryForm.descs = ''
      if (order) {
        if (order === 'ascending') {
          this.queryForm.ascs = column.sortBy
        } else {
          this.queryForm.descs = column.sortBy
        }
      }
      this.queryForm.current = 0
      this.doQuery()
    },
    handleCurrentChange(current) {
      this.queryForm.current = current
      this.doQuery()
    },
    handleSizeChange(size) {
      this.queryForm.size = size
      this.doQuery()
    },
    doQuery() {
      this.loading = true
      queryUserAccountWithDrawCashApply(this.queryForm).then(
        ({ data: { data } }) => {
          this.queryForm.current = data.current
          this.queryForm.pages = data.pages
          this.queryForm.total = data.total
          this.queryForm.size = data.size
          this.records = data.records
          this.loading = false
        }
      )
    },
    handleQueryById({ rowId }) {
      this.approveShow = false
      queryUserAccountWithDrawCashApplyDetail(rowId).then(
        ({ data: { code, data, msg } }) => {
          if (code === 0) {
            this.openShowDialog()
            this.showForm = data
          }
        }
      )
    },
    openShowDialog() {
      this.showForm = {}
      this.dialogShowFormVisible = true
      this.$refs.showForm && this.$refs.showForm.resetFields()
    },
    rejectDialog(rowId) {
      this.openRejectDialog()
      this.rejectForm.rowId = rowId
    },
    openRejectDialog() {
      this.rejectOrderButton = true
      this.dialogRejectFormVisible = true
      this.$refs.rejectForm && this.$refs.rejectForm.resetFields()
    },
    rejectOrder() {
      this.$refs.rejectForm.validate(valid => {
        if (valid) {
          this.rejectOrderButton = false
          rejectAccountWithDrawCashApply(this.rejectForm).then(
            ({ data: { data, msg } }) => {
              this.doQuery()
              this.dialogRejectFormVisible = false
              this.$message({
                showClose: true,
                message: msg,
                type: 'success'
              })
            }
          )
        } else {
          return false
        }
      })
      // this.$confirm('确认拒绝此申请?', '提示', {
      //   confirmButtonText: '确定',
      //   cancelButtonText: '取消',
      //   type: 'warning'
      // }).then(() => {

      // })
    },
    // approveApply(rowId) {
    //   queryUserAccountWithDrawCashApplyDetail(rowId).then(({ data: { code, data, msg }}) => {
    //     if (code === 0) {
    //       this.openShowDialog()
    //       this.showForm = data
    //     }
    //   })
    // },
    approveApply({ rowId, status }) {
      if (status === '0') {
        this.$confirm('确认通过此申请?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          approveAccountWithDrawCashApply(rowId).then(
            ({ data: { code, data, msg } }) => {
              if (code === 0) {
                this.dialogShowFormVisible = false
                this.doQuery()
                this.loading = true
              }
              this.$message({
                showClose: true,
                message: msg,
                type: 'success'
              })
            }
          )
        })
      } else {
        this.$message({
          showClose: true,
          message: '只能审核状态为为审核的订单！',
          type: 'error'
        })
      }
    }
  },
  components: {}
}
</script>

<style scoped></style>
